class Backend::RolesController < Backend::BaseController
  before_action :set_role, only: %i[show edit update destroy]

  def index
    @search = Role.all.ransack(params[:q])
    scope = @search.result
    @roles = scope.page(params[:page])
  end


  def new
    @role = Role.new
  end

  def create
    @role = Role.new(role_params)
    if @role.save
      redirect_to backend_roles_url, notice: "Role was successfully created."
    else
      render :new
    end
  end

  def edit;

  end


  def update
    if @role.update(role_params)
      redirect_to backend_roles_url, notice: "Role was successfully updated."
    else
      render :edit
    end
  end

  def destroy
    @role.destroy
    redirect_to backend_roles_url, notice: "Role was successfully destroyed."
  end

  private

  # Use callbacks to share common setup or constraints between actions.
  def set_role
    @role = Role.find(params[:id])
  end

  # Only allow a trusted parameter "white list" through.
  def role_params
    params.require(:role).permit(:name, permissions_attributes: {})
  end

end
